﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace PDS2
{
    public class DamageDisplay
    {
        List<Display> displays = new List<Display>();

         SpriteFont Font;

        public DamageDisplay(SpriteFont font)
        {
            Font = font;
        }

        public void AddDisplay(string damage, Vector2 pos, Color color)
        {
            displays.Add(new Display(
                Font, pos, color, damage));
        }

        public void Update(GameTime gameTime)
        {
            for (int i = 0; i < displays.Count; i++)
            {
                displays[i].Update(gameTime);

                if (!displays[i].IsAlive)
                {
                    displays.RemoveAt(i);
                }
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            foreach(Display display in displays)
            {
                display.Draw(spriteBatch);
            }
        }
    }

    public class Display
    {
        public Vector2 Position;
        SpriteFont font;
        public Color Color;
        string damage;

        public bool IsAlive = true;

        public Display(SpriteFont font, Vector2 pos, Color color, string damage)
        {
            this.font = font;
            this.Position = pos;
            this.Color = color;
            this.damage = damage;
        }

        public void Update(GameTime gameTime)
        {
            Color *= 0.98f;
            if (Color.A <= 0)
                IsAlive = false;
            Position.Y -= 0.7f;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(font, damage, Position, Color, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.00001f);
        }
    }
}
